﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.DataMining
{
    /// <summary>
    /// This class provides the selection of data out of a specified matrix.
    /// </summary>
    [Serializable]
    public class MatrixDataSelector : IDataSelector
    {
        /// <summary>
        /// The source matrix for the data selection.
        /// </summary>
        private Matrix sourceMatrix;

        /// <summary>
        /// Initializes a new instance of the <see cref="MatrixDataSelector"/> class.
        /// </summary>
        /// <param name="sourceMatrix">The source matrix for the data selection.</param>
        public MatrixDataSelector(Matrix sourceMatrix)
        {
            if (sourceMatrix == (Matrix) null)
            {
                throw new ArgumentNullException("sourceMatrix");
            }

            this.sourceMatrix = sourceMatrix;
        }

        /// <summary>
        /// Gets or sets the source matrix for the data selection.
        /// </summary>
        /// <value>The source matrix for the data selection.</value>
        public Matrix SourceMatrix
        {
            get { return sourceMatrix; }
            set { sourceMatrix = value; }
        }

        /// <summary>
        /// Gets the value at a specified position.
        /// </summary>
        /// <param name="row">The specified row index.</param>
        /// <param name="column">The specified column index.</param>
        /// <returns>The value at the specified position.</returns>
        public double GetValueAt(int row, int column)
        {
            return this.sourceMatrix.GetValueAtPosition(row, column);
        }

        /// <summary>
        /// Gets the number of rows of the data set.
        /// </summary>
        /// <returns>The number of rows of the data set.</returns>
        public int GetRowCount()
        {
            return this.sourceMatrix.Rows;
        }

        /// <summary>
        /// Gets the number of columns of the data set.
        /// </summary>
        /// <returns>The number of columns of the data set.</returns>
        public int GetColumnCount()
        {
            return this.sourceMatrix.Columns;
        }
    }
}